import request from '../../../utils/request'

export function login(data) {
  return request({
    url: '/api/user/login/',
    method: 'POST',
    data: data,
  })
}

// 通过token获取用户信息
// export function getInfo(token) {
export function getInfo() {
  return request({
    url: '/api/user/user/',
    method: 'GET',
    // params: { token },
  })
}

export function logout(data) {
  return request({
    url: '/api/user/logout/',
    method: 'post',
    data: {'token': data},
  })
}


export function superuserUserListApi() {
  // 用户中的超级用户列表
  return request({
    url: '/api/user/user/?is_superuser=True',
    method: 'GET',
  })
}

export function businessUserListApi() {
  // 用户中的商家用户列表
  return request({
    url: '/api/user/user/?is_superuser=False&is_business=True',
    method: 'GET',
  })
}

export function userBusinessListApi(business) {
  // 指定商家的用户列表
  return request({
    url: '/api/user/user/?business=' + business,
    method: 'GET',
  })
}

export function userBusinessStaffListApi(business) {
  // 指定商家的员工用户列表
  return request({
    url: '/api/user/user/?business=' + business + '&is_superuser=False&is_business=False&is_staff=True&is_customer=True&is_member=True',
    method: 'GET',
  })
}

export function userBusinessCustomerListApi(business) {
  // 指定商家的顾客用户列表
  return request({
    url: '/api/user/user/?business=' + business + '&is_superuser=False&is_business=False&is_staff=False&is_customer=True&is_member=False',
    method: 'GET',
  })
}

export function userBusinessMemberListApi(business) {
  // 指定商家的会员用户列表
  return request({
    url: '/api/user/user/?business=' + business + '&is_superuser=False&is_business=False&is_staff=False&is_customer=True&is_member=True',
    method: 'GET',
  })
}

export function userCreateApi(data) {
  // 用户信息创建接口
  return request({
    url: '/api/user/user/',
    method: 'POST',
    data: data
  })
}

export function userUpdateApi(data) {
  // 用户信息更新接口
  return request({
    url: '/api/user/user/' + data['username'] + '/',
    method: 'PATCH',
    data,
  })
}

export function userDeleteApi(username) {
  // 用户信息删除接口
  return request({
    url: '/api/user/user/' + username + '/',
    method: 'DELETE',
  })
}

export function userDetailApi(username) {
  // 用户信息详细接口——单个用户信息
  return request({
    url: '/api/user/user/' + username + '/',
    method: 'GET',
  })
}

export function usePhoneQueryBusinessInfoApi(phone) {
  // 使用电话号码查询商家信息接口
  return request({
    url: '/api/user/query/phone/',
    method: 'POST',
    data: {'phone': phone}
  })
}

export function userRetrievePasswordApi(data) {
  // 用户找回密码接口
  return request({
    url: '/api/user/retrieve-password/',
    method: 'POST',
    data: data,
  })
}

export function userModifyPasswordApi(data) {
  // 用户修改密码接口
  return request({
    url: '/api/user/modify-password/',
    method: 'POST',
    data: data,
  })
}
